package com.qdxwx.models.enums;

import com.qdxwx.common.utils.TKString;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author ZhiYong
 * @createTime 2021/12/9
 * @description
 */
public enum ModuleType {

    UNKNOWN("未知"),
    ARTICLE("文章"),
    COURSE("课程"),
    BOOK("教材"),
    PICTURE("图片"),
    DOCUMENT("文档");

    private final String name;

    private final static Logger logger = LoggerFactory.getLogger(ModuleType.class);

    ModuleType(String name) {
        this.name = name;
    }

    public String getName() {
        return this.name;
    }

    /**
     * 根据值获取对像String
     * @param value 值
     * @return default null
     */
    public static String getString(String value) {
        ModuleType type = get(value);
        if (type == null)
            return null;
        else
            return type.toString();
    }

    //根据值获取对像
    public static ModuleType get(String value) {
        if (TKString.isEmpty(value)) return null;
        try {
            return ModuleType.valueOf(value.toUpperCase());
        } catch (Exception ex) {
            return null;
        }
    }

    public static String getName(int moduleId) {
        try {
            return ModuleType.values()[moduleId].getName();
        } catch (Exception ex) {
            logger.error("module not find id:" + moduleId, ex);
            return ModuleType.UNKNOWN.getName();
        }
    }
}
